"""
@release: fsray-api-alpha
@file: area.py
@author: lingdubing
@desc: 操作区域行为的接口层
@character: utf-8
"""

from models.models import Area
from fastapi import  APIRouter, Depends
from schemas.response import *
from core.Auth import check_permission
from config import settings
from schemas.area_schemas import *
from service.AreaService import AreaService

router = APIRouter()

@router.post("/area_list", summary="获取区域列表", response_model=ReturnDataModel,dependencies=[Depends(check_permission)])
async def get_area_list(query: AreaPaingtionModel):

    area_service = AreaService()
    area_list, total = area_service.get_paginated(page=query.page, page_size=query.page_size)

    final_list = []
    for result in area_list:
        area_info = {
            "area_id": result.area_id,
            "area_name": result.area_name,
            "area_desc": result.area_desc,
            "create_time": result.create_time,
            "update_time": result.update_time
        }
        final_list.append(area_info)

    return ReturnDataModel(code=STATUS_CODE["success"],message="获取区域列表成功",data=final_list,
                           success=True, total=total)




